home *** CD-ROM | disk | FTP | other *** search
- // xorConsoleTesting.cpp
- // Automatically generated from breadboard by NeuroSolutions.
-
- #include "NSLib.h"
-
- void inputFileAccess(NSFloat *, int, int);
- void activeOutputProbeAccess(NSFloat *, int, int);
- BOOL networkStopped=FALSE;
- unsigned short int weightFileVersion=225;
-
- // Component Construction
- Axon inputAxon;
- FunctionIO inputFile;
- FullSynapse hidden1Synapse;
- TanhAxon hidden1Axon;
- FullSynapse outputSynapse;
- TanhAxon outputAxon;
- FunctionIO activeOutputProbe;
-
- int main() {
- srand((unsigned)time(NULL));
-
- // Component Initialization
- inputAxon.setRows(2);
- inputFile.setFunction((void*)inputFileAccess);
- inputFile.setMode(READ);
- inputFile.setSpatialDimension(2,1);
- hidden1Axon.setRows(2);
- outputAxon.setRows(1);
- activeOutputProbe.setFunction((void*)activeOutputProbeAccess);
- activeOutputProbe.setMode(WRITE);
- activeOutputProbe.setSpatialDimension(1,1);
- FILE *loadStream = fopen("xorConsoleTesting.nsw","r");
- if (!loadStream) {
- fprintf(stderr, "Could not open weight file xorConsoleTesting.nsw");
- exit(1);
- }
- weightFileVersion = getWeightFileVersion(loadStream);
-
- // Load Normalization Coefficients of Files
- inputFile.loadWeights(seekComponent(loadStream, "File", "inputFile"),weightFileVersion);
-
- // Component Interconnection
- inputAxon.setPreActivityAccess(&inputFile);
- outputAxon.setActivityAccess(&activeOutputProbe);
- inputAxon.setNext(&hidden1Synapse);
- hidden1Synapse.setLast(&inputAxon);
- hidden1Synapse.setNext(&hidden1Axon);
- hidden1Axon.setLast(&hidden1Synapse);
- hidden1Axon.setNext(&outputSynapse);
- outputSynapse.setLast(&hidden1Axon);
- outputSynapse.setNext(&outputAxon);
- outputAxon.setLast(&outputSynapse);
-
- // Load Axon Weights
- inputAxon.loadWeights(seekComponent(loadStream, "Axon", "inputAxon"),weightFileVersion);
- hidden1Axon.loadWeights(seekComponent(loadStream, "TanhAxon", "hidden1Axon"),weightFileVersion);
- outputAxon.loadWeights(seekComponent(loadStream, "TanhAxon", "outputAxon"),weightFileVersion);
-
- // Load Synapse Weights
- hidden1Synapse.loadWeights(seekComponent(loadStream, "FullSynapse", "hidden1Synapse"),weightFileVersion);
- outputSynapse.loadWeights(seekComponent(loadStream, "FullSynapse", "outputSynapse"),weightFileVersion);
- fclose(loadStream);
-
- // Get Ready to Run Network
-
- // Run Network
- int epochs = 110;
- int exemplars = 4;
- int epochsPerCV = 0;
- for (int epoch=0; epoch<epochs; epoch++) {
- for (int exemplar=0; exemplar<exemplars; exemplar++) {
- inputAxon.fire();
- if (networkStopped) {
- goto ConcludeFiring;
- }
- }
- if (networkStopped)
- goto ConcludeFiring;
- }
-
- ConcludeFiring:
-
-
- return 0;
- }
-
- void inputFileAccess(NSFloat *data, int rows, int cols) {
- // This function is called each time the inputAxon's Pre-Activity data changes
- // This function's code was written after NeuroSolutions generated the code for the BB
- // (Begin)
- int length,
- i;
- char response[128];
-
- length = rows*cols;
- printf("Enter the space-delimited data samples ('exit' to quit)):\n");
- scanf("%s",response);
- if (strcmp(response,"exit") != 0) {
- sscanf(response,"%f", data);
- for (i=1; i<length; i++)
- scanf("%f", data+i);
- }
- else
- networkStopped=TRUE;
- // (End)
- }
-
- void activeOutputProbeAccess(NSFloat *data, int rows, int cols) {
- // This function is called each time the outputAxon's Activity data should be changed
- // This function's code was written after NeuroSolutions generated the code for the BB
- // (Begin)
- int j,
- i;
-
- printf("Network output:\n");
- for (i=0; i<rows; i++) {
- for (j=0; j<cols; j++)
- printf("%f ", data[i*cols + j]);
- printf("\n");
- }
- // (End)
- }
-
-